//
//  UIResponder+ZZUtil.m
//  ZZKitDemo
//
//  Created by hfzhangzhang on 2018/8/13.
//  Copyright © 2018年 hfzhangzhang. All rights reserved.
//

#import "UIResponder+ZZUtil.h"

@implementation UIResponder (ZZUtil)

@end
@implementation UIResponder (Controller)

- (UIViewController *)viewController {
    return (UIViewController *)[self zz_nearestResponderOfClass:[UIViewController class]];
}

- (UINavigationController *)navigationController {
    return (UINavigationController *)[self zz_nearestResponderOfClass:[UIViewController class]];
}

- (UITabBarController *)tabBarController {
    return (UITabBarController *)[self zz_nearestResponderOfClass:[UITabBarController class]];
}

- (UIResponder *)zz_nearestResponderOfClass:(Class)clazz {
    UIResponder *responder = self;
    while (responder && ![responder isKindOfClass:clazz]) {
        responder = [responder nextResponder];
    }
    return (UIViewController *)responder;
}

@end
